using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using SILAS.Entidades;

namespace SILAS.DAO.Mapping
{
    public class EmpleadoMap : EntityTypeConfiguration<Empleado>
    {
        public EmpleadoMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.Nombre)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.ApPaterno)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.ApMaterno)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.DNI)
                .IsRequired()
                .IsFixedLength()
                .HasMaxLength(8);

            this.Property(t => t.Area)
                .HasMaxLength(50);

            this.Property(t => t.Email)
                .HasMaxLength(50);

            this.Property(t => t.Celular)
                .HasMaxLength(20);

            // Table & Column Mappings
            this.ToTable("Empleado");
            this.Property(t => t.Id).HasColumnName("IdEmpleado");
            this.Property(t => t.Nombre).HasColumnName("Nombre");
            this.Property(t => t.ApPaterno).HasColumnName("ApPaterno");
            this.Property(t => t.ApMaterno).HasColumnName("ApMaterno");
            this.Property(t => t.DNI).HasColumnName("DNI");
            this.Property(t => t.Area).HasColumnName("Area");
            this.Property(t => t.Email).HasColumnName("Email");
            this.Property(t => t.Celular).HasColumnName("Celular");
            this.Property(t => t.IdCargo).HasColumnName("IdCargo");

            // Relationships
            this.HasRequired(t => t.Cargo)
                .WithMany(t => t.Empleadoes)
                .HasForeignKey(d => d.IdCargo);

        }
    }
}